function createTSConnectionHeatmap_Fig5CD()
% Creates a heatmap of tumor suppressor connectivity from 11 DAS sources that provides protein interaction data
%
% createTSConnectionHeatmap() builds a heatmap for tumor suppressor
% connectivity retrieving data from 11 DAS sources that provides protein
% interactions data. The heatmap exhibits how connected is each TS, and
% also allows to assess the degree of reliability for a specific TS-nonTS
% interaction.
%
% SYNTAX: [] = createTSConnectionHeatmap()
%
% NOTE: assembling these 11 TS networks can take several minutes. To load
% the pre-built dataset uncomment the following line below:
%                load TSNetwork_Heatmap.mat conn nonTS tsGenes;
%
% See also createTumorSuppressorsNet(), tumorSuppressorNetwork_Fig5AB()
%  
%    DASMiner: DAS library and browser for Matlab.
%    Diogo Veiga, Jan 2009.


% load TSNetwork_Heatmap.mat conn nonTS tsGenes;

global tsGenes;
global tsEntrezID;

nets = struct('graph',{},'label',{});
nets(1).graph = createTumorSuppressorsNet('http://dasmi.bioinf.mpi-inf.mpg.de/das','ddi',false);
nets(1).label = 'DDI';
nets(2).graph = createTumorSuppressorsNet('http://dasmi.bioinf.mpi-inf.mpg.de/das','hprd',false);
nets(2).label = 'HPRD';
nets(3).graph = createTumorSuppressorsNet('http://dasmi.bioinf.mpi-inf.mpg.de/das','bioverse',false);
nets(3).label = 'Bioverse';
nets(4).graph = createTumorSuppressorsNet('http://dasmi.bioinf.mpi-inf.mpg.de/das','bioverse-core',false);
nets(4).label = 'Bioverse-core';
nets(5).graph = createTumorSuppressorsNet('http://dasmi.bioinf.mpi-inf.mpg.de/das','ophid',false); 
nets(5).label = 'OPHID';
nets(6).graph = createTumorSuppressorsNet('http://dasmi.bioinf.mpi-inf.mpg.de/das','point',false);
nets(7).label = 'Point';
nets(7).graph = createTumorSuppressorsNet('http://dasmi.bioinf.mpi-inf.mpg.de/das','homomint',false); 
nets(7).label = 'HomoMINT';
nets(8).graph = createTumorSuppressorsNet('http://dasmi.bioinf.mpi-inf.mpg.de/das','ccsb-hi1',false);
nets(8).label = 'CCSB-HI1';
nets(9).graph = createTumorSuppressorsNet('http://dasmi.bioinf.mpi-inf.mpg.de/das','sanger',false);
nets(9).label = 'Sanger';
nets(10).graph = createTumorSuppressorsNet('http://dasmi.bioinf.mpi-inf.mpg.de/das','himap',false);
nets(10).label = 'Himap';
nets(11).graph = createTumorSuppressorsNet('http://dasmi.bioinf.mpi-inf.mpg.de/das','himap-core',false);
nets(11).label = 'Himap-core';


%Matrix holds connectivity weight
conn = []; %initial state 
nonTS = {}; %holds labels for non-TS genes


for i=1:size(nets,2)

    for j=1:size(nets(i).graph.Nodes)

        if(isempty(strmatch(nets(i).graph.Nodes(j).Label,tsGenes,'exact'))) %non TS gene

            anc = getancestors(nets(i).graph.Nodes(j),1); % TS interacting with this TS gene
            idxNonTS = strmatch(nets(i).graph.Nodes(j).Label,nonTS,'exact');
           
            if(isempty(idxNonTS)) % new non-TS
                conn = [conn; zeros(1,size(tsGenes,2))]; %add new row to conn matrix
                nonTS = [nonTS nets(i).graph.Nodes(j).Label]; %add new label
                idxNonTS = strmatch(nets(i).graph.Nodes(j).Label,nonTS,'exact'); %get new index
            end
            
            for k=1:size(anc)
                idxTS = strmatch(anc(k).ID,tsEntrezID,'exact');
                if (~isempty(idxTS))
                    conn(idxNonTS,idxTS) = conn(idxNonTS,idxTS) + 1;
                end
            end

        end
    end

end


%Heatmap of protein-TS interaction
figure;
img = imagesc(conn);
set(gca,'XTickLabel',tsGenes);
%set(gca,'YTickLabel',nonTS);
set(gca,'YTickLabel',{});
set(gca,'YTick',[1:2403]);
set(gca,'XTick',[1:22]);
set(gca,'FontSize',8);
colormap('hot');
colorbar

%Heatmap: closer look to protein-TS interactions for the first 30 non-TS genes
figure;
img = imagesc(conn(1:30,:));
set(gca,'XTickLabel',tsGenes);
set(gca,'YTickLabel',nonTS(1:30));
set(gca,'YTick',[1:30]);
set(gca,'XTick',[1:22]);
set(gca,'FontSize',8);
colormap('hot');
colorbar











